package com.xq.aop.xml;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * @author xq
 * @version 1.0
 * @date 2021/4/6 14:46
 * @description 循环通知类
 */
public class MyRoundAdvise implements MethodInterceptor {

    /**
     * 调用循环通知
     * @param methodInvocation 方法调用
     * @return 返回循环通知
     * @throws Throwable
     */
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        // 得到目标方法
        // Method method = methodInvocation.getMethod();
        // 得到参数
        // Object[] arguments = methodInvocation.getArguments();
        before();
        // 开始执行
        Object proceed = methodInvocation.proceed();
        after();
        return proceed;
    }

    /**
     * 前置增强
     */
    public void before() {
        System.out.println("先前拿水果种子");
    }

    /**
     * 后置增强
     */
    public void after() {
        System.out.println("水果播种后浇水");
    }
}
